package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhwyChargeitemRentalcontract;
import com.ruoyi.system.service.IZhwyChargeitemRentalcontractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同与收费项关联中间桥Controller
 * 
 * @author ruoyi
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/rentalcontractMiddle/rentalcontract_middle")
public class ZhwyChargeitemRentalcontractController extends BaseController
{
    @Autowired
    private IZhwyChargeitemRentalcontractService zhwyChargeitemRentalcontractService;

    /**
     * 查询合同与收费项关联中间桥列表
     */
    @PreAuthorize("@ss.hasPermi('rentalcontractMiddle:rentalcontract_middle:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhwyChargeitemRentalcontract zhwyChargeitemRentalcontract)
    {
        startPage();
        List<ZhwyChargeitemRentalcontract> list = zhwyChargeitemRentalcontractService.selectZhwyChargeitemRentalcontractList(zhwyChargeitemRentalcontract);
        return getDataTable(list);
    }

    /**
     * 导出合同与收费项关联中间桥列表
     */
    @PreAuthorize("@ss.hasPermi('rentalcontractMiddle:rentalcontract_middle:export')")
    @Log(title = "合同与收费项关联中间桥", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhwyChargeitemRentalcontract zhwyChargeitemRentalcontract)
    {
        List<ZhwyChargeitemRentalcontract> list = zhwyChargeitemRentalcontractService.selectZhwyChargeitemRentalcontractList(zhwyChargeitemRentalcontract);
        ExcelUtil<ZhwyChargeitemRentalcontract> util = new ExcelUtil<ZhwyChargeitemRentalcontract>(ZhwyChargeitemRentalcontract.class);
        util.exportExcel(response, list, "合同与收费项关联中间桥数据");
    }

    /**
     * 获取合同与收费项关联中间桥详细信息
     */
    @PreAuthorize("@ss.hasPermi('rentalcontractMiddle:rentalcontract_middle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zhwyChargeitemRentalcontractService.selectZhwyChargeitemRentalcontractById(id));
    }

    /**
     * 新增合同与收费项关联中间桥
     */
    @PreAuthorize("@ss.hasPermi('rentalcontractMiddle:rentalcontract_middle:add')")
    @Log(title = "合同与收费项关联中间桥", businessType = BusinessType.INSERT)
    @GetMapping
    public AjaxResult add(@RequestParam("rid") Long rid,@RequestParam("cid") Long[] cid)
    {
        ZhwyChargeitemRentalcontract cr = new ZhwyChargeitemRentalcontract();
        cr.setRentalcontractId(rid);
        int s = 0;
        for(int i = 0; i < cid.length; i ++){
            cr.setChargeitemId(cid[i]);
           s = zhwyChargeitemRentalcontractService.insertZhwyChargeitemRentalcontract(cr);
        }
        return toAjax(s);
    }

    /**
     * 修改合同与收费项关联中间桥
     */
    @PreAuthorize("@ss.hasPermi('rentalcontractMiddle:rentalcontract_middle:edit')")
    @Log(title = "合同与收费项关联中间桥", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhwyChargeitemRentalcontract zhwyChargeitemRentalcontract)
    {
        return toAjax(zhwyChargeitemRentalcontractService.updateZhwyChargeitemRentalcontract(zhwyChargeitemRentalcontract));
    }

    /**
     * 删除合同与收费项关联中间桥
     */
    @PreAuthorize("@ss.hasPermi('rentalcontractMiddle:rentalcontract_middle:remove')")
    @Log(title = "合同与收费项关联中间桥", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhwyChargeitemRentalcontractService.deleteZhwyChargeitemRentalcontractByIds(ids));
    }
}
